/**
 * 
 */
package field;

/**
 * Event has three components: time to happen, moving object and event type.
 * They are comparable to each other.
 * 
 * @author Xiaohui
 * 
 */

public class MyEvent implements Comparable {

	double timeToHappen;
	MovingObject mo_from;
	MovingObject mo_to;
	MyEventType type;
	MyEvent previous;
	MyEvent next;

	public MyEvent(double timeToHappen, MovingObject mo_from,
			MovingObject mo_to, MyEventType type) {
		this.timeToHappen = timeToHappen;
		this.mo_from = mo_from;
		this.mo_to = mo_to;
		this.type = type;
		previous = null;
		next = null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Object arg0) {
		if (arg0 instanceof MyEvent) {
			MyEvent e = (MyEvent) arg0;
			if (this.timeToHappen > e.timeToHappen)
				return 1;
			else if (this.timeToHappen == e.timeToHappen)
				return 0;
			else
				return -1;
		} else {
			throw new RuntimeException(
					"In MyEvent compareTo(), argument is not a MyEvent object");
		}
	}

	/**
	 * @return the timeToHappen
	 */
	public double getTimeToHappen() {
		return timeToHappen;
	}

	/**
	 * @param timeToHappen
	 *            the timeToHappen to set
	 */
	public void setTimeToHappen(double timeToHappen) {
		this.timeToHappen = timeToHappen;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		String event = "";
		if (this.type == MyEventType.enter) {
			event = "enter";
		} else {
			event = "exit";
		}
		// return this.timeToHappen + ": " + this.mo.oid + " " + event;
		return this.timeToHappen + ", "+mo_from.oid+", " +mo_to.oid+ "," + event;
	}

}
